function refresh() {
    tableIn.reload('btable');
}

$(function () {
    $.ajax({
        type:'get',
        url:'/microcircle/countAll',
        success:function (res){
            $('#count1').val(res.state);
        }
    })

    $.ajax({
        type:'get',
        url:'/microcircle/countpeople',
        success:function (res){
            $('#count2').val(res.state);
        }
    })

    $.ajax({
        type:'get',
        url:'/microcircle/counttoday',
        success:function (res){
            $('#count3').val(res.state);
        }
    })

    $.ajax({
        type:'get',
        url:'/microcircle/counttodaypeople',
        success:function (res){
            $('#count4').val(res.state);
        }
    })
})

$(function () {
    number('/microcircle/countAll','#qb')
})

$(function () {
    number('/microcircle/countadopt','#ytg')
})

$(function () {
    number('/microcircle/countintercept','#ylj')
})

$(function () {
    number('/microcircle/countdelete','#ysc')
})

function number(a,b){
    $(function () {
        $.ajax({
            type:'get',
            url:a,
            success:function (res){
                $(b).text(res.state);
            }
        })
    })
}

var tableIn = null;
layui.use(['table','form'], function () {
    var table = layui.table;
    var form = layui.form;

    tableIn = table.render({
        elem: '#commenttable',
        url: '/microcircle/get',
        toolbar: true,
        id: 'btable',
        page: {
            limit: 10,
            limits: [5, 10, 15],
            group: 10
        },
        cols: [
            [
                {field: "userAccount", title: '成员账号'},
                {field: "userNickname", title: '昵称'},
                {field: "productName", title: '所属商品'},
                {field: "commentDate", title: '发言时间'},
                {field: "content", title: '发言内容'},
                {field: "status", title: '状态',templet:function (obj){
                        if (obj.status == 1){
                            return "已通过";
                        }if (obj.status == 2){
                            return "已拦截";
                        }if (obj.status == 3){
                            return "已删除";
                        }
                    }},
                {toolbar: '#bardemo', title: "操作"}
            ]
        ],
        parseData: function (res) {
            return {
                "code": res.state,
                "msg": res.Message,
                "count": res.total,
                "data": res.data
            };
        },
    })


    table.on("tool(equip)", function (obj) {
        var event = obj.event;

        if (event === 'lj') {

            $.ajax({
                type:'get',
                url: "/microcircle/intercep",
                data: {"id":obj.data.id},
                success:function (){
                    refresh();
                    console.log(obj.data);
                }
            })
        }else if (event === 'tg'){

            $.ajax({
                type:'get',
                url: "/microcircle/adopt",
                data: {"id":obj.data.id},
                success:function (){
                    refresh();
                }
            })
        }else if (event === 'sc'){
            $.ajax({
                type:'get',
                url: "/microcircle/delete",
                data: {"id":obj.data.id},
                success:function (){
                    refresh();
                }
            })
        }
    })
});

$(document).on("click","button",function(){
    $("#button1").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button2").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button3").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button4").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button5").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button6").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

function qb(){
    render('/microcircle/countAll','/microcircle/get','/microcircle/countpeople','/microcircle/counttoday','/microcircle/counttodaypeople');
}

function ytg(){
    render('/microcircle/countadopt','/microcircle/getadopt','/microcircle/countpeopleadopt','/microcircle/counttodayadopt','/microcircle/counttodaypeopleadopt');
}

function ylj(){
    render('/microcircle/countintercept','/microcircle/getintercept','/microcircle/countpeopleintercept','/microcircle/counttodayintercept','/microcircle/counttodaypeopleintercept');
}

function ysc(){
    render('/microcircle/countdelete','/microcircle/getdelete','/microcircle/countpeopledelete','/microcircle/counttodaydelete','/microcircle/counttodaypeopledelete');
}

function qdyh(){
    render('/microcircle/countreceptione','/microcircle/reception','/microcircle/countpeoplereceptione','/microcircle/counttodayreceptione','/microcircle/counttodaypeoplereceptione');
}

function glry(){
    render('/microcircle/countbackstage','/microcircle/backstage','/microcircle/countpeoplebackstage','/microcircle/counttodaybackstage','/microcircle/counttodaypeoplebackstage');
}

function render(a,b,c,d,e){
    $(function () {
        $.ajax({
            type:'get',
            url: a,
            success:function (res){
                $('#count1').val(res.state);
            }
        })

        $.ajax({
            type:'get',
            url: c,
            success:function (res){
                $('#count2').val(res.state);
            }
        })

        $.ajax({
            type:'get',
            url: d,
            success:function (res){
                $('#count3').val(res.state);
            }
        })

        $.ajax({
            type:'get',
            url: e,
            success:function (res){
                $('#count4').val(res.state);
            }
        })
    })

    layui.use(['table','form'], function () {
        var table = layui.table;
        var form = layui.form;

        tableIn = table.render({
            elem: '#commenttable',
            url: b,
            toolbar: true,
            id: 'btable',
            page: {
                limit: 10,
                limits: [5, 10, 15],
                group: 10
            },
            cols: [
                [
                    {field: "userAccount", title: '成员账号'},
                    {field: "userNickname", title: '昵称'},
                    {field: "productName", title: '所属商品'},
                    {field: "commentDate", title: '发言时间'},
                    {field: "content", title: '发言内容'},
                    {field: "status", title: '状态',templet:function (obj){
                            if (obj.status == 1){
                                return "已通过";
                            }if (obj.status == 2){
                                return "已拦截";
                            }if (obj.status == 3){
                                return "已删除";
                            }
                        }},
                    {toolbar: '#bardemo', title: "操作"}
                ]
            ],
            parseData: function (res) {
                return {
                    "code": res.state,
                    "msg": res.Message,
                    "count": res.total,
                    "data": res.data
                };
            },
        })


        table.on("tool(equip)", function (obj) {
            var event = obj.event;

            if (event === 'lj') {

                $.ajax({
                    type:'get',
                    url: "/microcircle/intercep",
                    data: {"id":obj.data.id},
                    success:function (){
                        refresh();
                        console.log(obj.data);
                    }
                })
            }else if (event === 'tg'){

                $.ajax({
                    type:'get',
                    url: "/microcircle/adopt",
                    data: {"id":obj.data.id},
                    success:function (){
                        refresh();
                    }
                })
            }else if (event === 'sc'){
                $.ajax({
                    type:'get',
                    url: "/microcircle/delete",
                    data: {"id":obj.data.id},
                    success:function (){
                        refresh();
                    }
                })
            }
        })
    });
}

